<template>
	
	<div>
		
		<div>
			<h2>登分</h2>
			
			<h3>当前班级：{{data.clzname}}</h3>
			
			<h3>当前课程：{{data.cname}}</h3>
			
			<button @click="postBatch()">批量提交</button>
			
			<table border="1px">
				<tr>
					<th>学生账号</th>
					<th>学生姓名</th>
					<th>分数</th>
					<th>旧的分数</th>
					<th>登分时间</th>
				</tr>
				<tr v-for="(x,idx) in data.marks">
					<td>{{x.sno}}</td>
					<td>{{x.user.uname}}</td>
					<td><input v-model="x.score" type="text" ></td>
					<td>{{x.oldScore}}</td>
					<td>{{x.tpost}}</td>
				</tr>
			</table>
			
				
			
		</div>

	</div>
	
</template>

<script setup>
	
	import {ref,reactive,onMounted} from 'vue';
	import {$get} from '@/ajax';
	import {$postj} from '@/ajax';
	import myalert from '@/store/index.js';
	import {useRoute} from "vue-router";
	
	
	
	const route = useRoute();
	
	console.log(route.query.clzno)
	

	
	const data = reactive({
		clzname:'',
		cname:'',
		marks:[],
		// mark:{id:0,oldScore:0}
	})
	
	function postBatch(){
		let arr = [];
		
		for (var i = 0; i < data.marks.length; i++) {
			let x = data.marks[i];
			
			if(x.score != x.oldScore){
				
				console.log("修改了分数 == " + x.user.uname)
				
				// x.tpost = new Date;  //修改时间
				console.log("x.id==" + x.id)
				console.log("x.score==" + x.score)
				x.oldScore = x.score
				 
				arr.push( {id:x.id,sno:x.sno,cno:x.course.cno,score:x.score} );
				
			}
		}
		
		console.log("---------------")
		console.log(arr)
		console.log("------------")
		
		$postj("/api/fore/tea/addMark",arr)
		.then((resp)=>{
		console.log("666666");
		})
	}
	

	
		computed:{
			
			
				onMounted(()=>{
		console.log("=====")
		console.log(route.query.clzno)
		
		$get("/api/public/getClzs")
		.then((resp)=>{
			
			let clzs = resp.data.data;
			
			console.log("11111")
			
			for (var i = 0; i < clzs.length; i++) {
				if(clzs[i].clzno == route.query.clzno){
					data.clzname = clzs[i].clzname;
					console.log("2222")
				}
			}console.log("获取路由传递的参数== " + data.clzname)
			
		})
		
		$get("/api/public/getCourses")
		.then((resp)=>{
			
			let courses = resp.data.data;
			
			console.log("11111")
			
			for (var i = 0; i < courses.length; i++) {
				if(courses[i].cno == route.query.cno){
					data.cname = courses[i].cname;
					console.log("2222")
				}
			}console.log(data.cname)
			
		})
		
		console.log("clzno=== " + route.query.clzno)
		console.log("cno==== " + route.query.cno)
		
		$get("/api/fore/tea/findMark?clzno=" + route.query.clzno + "&cno=" + route.query.cno).then((resp)=>{
		
			data.marks = resp.data.data;
			
			for (var i = 0; i < data.marks.length; i++) {
				let x = data.marks[i];
				x.oldScore = x.score;  //把成绩复制
				console.log(x)
			}
		
			console.log("999999999999999")
			
			console.log(data.marks)
			
		})
		

		
		
		
	})
		}
	
	
	
</script>
	
	
	


<style>
</style>
